<?php
/*
	[BuyPg] (C) 2010-2011 Buypg
	$Id: NbTousuModel.class.php 2011-5-16 10:24:29 wufujun $
*/
if (!defined('THINK_PATH')) {
	exit('Access Denied');
}

class NbTousuModel extends Model{
	//自动验证
	protected $_validate = array(
		array('tousu_title','require','投诉标题不能为空',0),
		array('site_id','require','操作错误',0),
		array('class_id','require','请选择分类',0),
		array('tousu_content','require','投诉内容不能为空',0),
	);
	
	//自动填充
	protected $_auto = array(
		array('tousu_content' , 'formattext' , 3 , 'callback'),
		array('user_id' , 'getUid' , 1 , 'callback'),
		array('zhuanti_id' , 'getZhuanTiId' , 1 , 'callback'),
		array('nb_class_id' , 'getNbClassId' , 1 , 'callback'),
		array('tousu_dt' , 'getNowTime' , 1 , 'function'),
		array('tousu_date' ,'getTimeToStr' , 1 , 'function'),
		array('user_ip' , 'get_client_ip' , 1 , 'function'),
	);
	
	//获取UID
	protected function getUid(){
		global $_SGLOBAL;
		return $_SGLOBAL['G_uid'];
	}
	
	//格式化内容
	protected function formattext($str){
		import("@.ORG.Input");
		return Input::nl2Br(Input::deleteHtmlTags($str));
	}
	
	//获取专题ID
	protected function getZhuanTiId(){
		$siteid = $_POST['site_id'];
		$DbSite = M("NbSite");
		$arrSite = $DbSite->where("site_id = $siteid and flag = 1")->find();
		$ZhuanTiId = 0;
		if($arrSite){
			$ZhuanTiId = $arrSite['zhuanti_id'];
		}
			
		return $ZhuanTiId;
	}
	
	//获取NbClassID
	protected function getNbClassId(){
		$siteid = $_POST['site_id'];
		$DbSite = M("NbSite");
		$arrSite = $DbSite->where("site_id = $siteid and flag = 1")->find();
		$NbClassId = 0;
		if($arrSite){
			$NbClassId = $arrSite['class_id'];
		}
		return $NbClassId;
	}
}
?>